﻿<UserControl x:Class="CncConvProg.View.Lavorazioni.OperazioneScreen.Common.OperazioneView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ab="clr-namespace:CncConvProg.View.AttachedProperty" xmlns:Resources="clr-namespace:MecPrev.Resources;assembly=MecPrev.Resources" mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="600"  >
    <UserControl.Resources>
        <Style x:Key="ImageStyle">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=GruppoMateriale}" Value="0">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_p.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path= GruppoMateriale}" Value="1">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_m.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=GruppoMateriale}" Value="2">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_k.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=GruppoMateriale}" Value="3">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_n.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=GruppoMateriale}" Value="4">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_h.png"/>
                </DataTrigger>

                <DataTrigger Binding="{Binding Path=GruppoMateriale}" Value="5">
                    <Setter Property="Image.Source" Value="pack://application:,,,/CncConvProg.View;component/Images/Gui/Material/mat_s.png"/>
                </DataTrigger>

            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <DockPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
            <TextBlock Text="{x:Static Resources:EditWorkRes.OperationAb}" FontSize="14" Margin="5" />
            <CheckBox IsChecked="{Binding Path=OperationAbilited}" VerticalAlignment="Center"/>
        </StackPanel>
        <Grid IsEnabled="{Binding Path=OperationAbilited}">
            <Grid.Resources>
                <ResourceDictionary >
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary  Source="OperazioneViewResources.xaml">
                        </ResourceDictionary>
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </Grid.Resources>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" MinHeight="100" />
                <RowDefinition Height="200*" />
            </Grid.RowDefinitions>


            <Menu Grid.Row="1" Grid.ColumnSpan="2">
                <Menu.Resources>
                    <Style x:Key="newPhaseItemContainerStyle">
                        <Setter Property="MenuItem.Header" Value="{Binding Path=ToolDescription}"/>
                        <Setter Property="MenuItem.Command" Value="{Binding Path=DataContext.SetThisToolCmd, RelativeSource={RelativeSource AncestorLevel=1, AncestorType={x:Type UserControl}, Mode=FindAncestor}}"/>
                        <Setter Property="MenuItem.CommandParameter" Value="{Binding}"/>
                    </Style>
                </Menu.Resources>
                <MenuItem Header="{x:Static Resources:EditWorkRes.AutoTool}" Command="{Binding Path=AutoToolFindCmd}">
                    <MenuItem.Icon>
                        <Image Source="pack://application:,,,/CncConvProg.View;component/Images/gui/Search.png" Height="18" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{x:Static Resources:EditWorkRes.Save}">
                    <MenuItem.Icon>
                        <Image Source="pack://application:,,,/CncConvProg.View;component/Images/gui/save_16.png" Height="18" />
                    </MenuItem.Icon>
                    <MenuItem Header="{x:Static Resources:EditWorkRes.OverwriteParameter}" Command="{Binding Path=SaveParameterCmd}" CommandParameter="0" />
                    <MenuItem Header="{x:Static Resources:EditWorkRes.CreateNewTool}" Command="{Binding Path=SaveParameterCmd}" CommandParameter="1" />
                </MenuItem>
                <MenuItem Header="{x:Static Resources:EditWorkRes.SelectTool}" ItemsSource="{Binding Path=UtensiliCompatibili}" ItemContainerStyle="{StaticResource ResourceKey=newPhaseItemContainerStyle}">
                </MenuItem>
            </Menu>
            <GroupBox Header="{x:Static Resources:EditWorkRes.ToolDetailGroup}" Margin="5" Grid.Row="2" HorizontalAlignment="Left" MinWidth="200">
                <ContentControl Content="{Binding Path=UtensileViewModel}"/>
            </GroupBox>

            <Image Grid.Column="1" Grid.Row="2" Height="150" MaxWidth="200" VerticalAlignment="Top" Source="{Binding Path= SelectedItem.Tag}" Grid.RowSpan="1" HorizontalAlignment="Right"/>

            <TabControl MinWidth="250" Grid.Row="3" Grid.Column="1"  Margin="5" DataContext="{Binding Path=UtensileViewModel}" HorizontalAlignment="Right">
                <TabItem>
                    <TabItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Style="{StaticResource ResourceKey=ImageStyle}" DataContext="{Binding Path=ToolParameterViewModel.Materiale}" Height="22"  Width="22" Grid.Row="0" Grid.Column="1" VerticalAlignment="Bottom"/>
                            <TextBlock Text="{x:Static Resources:EditWorkRes.ToolParameter}" VerticalAlignment="Center" Margin="5,0,0,0"/>
                        </StackPanel>
                    </TabItem.Header>
                    <ContentControl Content="{Binding Path=ToolParameterViewModel}"/>
                </TabItem>
                <TabItem Header="{x:Static Resources:EditWorkRes.ToolWear}" >
                    <StackPanel DataContext="{Binding Path=ToolParameterViewModel}">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Costo Utensile : " MinWidth="100" Height="20" />
                            <TextBox ab:AttachedProperties.AutoSelectText="True" Name="tbCostoUtensile" Text="{Binding Path=CostoUtensile}" MinWidth="100" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" >
                            <TextBlock Text="Metri Vita : " MinWidth="100" Height="20" />
                            <TextBox ab:AttachedProperties.AutoSelectText="True" Name="tbMetri" Text="{Binding Path=MetriVitaUtensile}" MinWidth="100" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Tempo Vita : " MinWidth="100" Height="20" />
                            <TextBox ab:AttachedProperties.AutoSelectText="True" Name="tbTempoVita" Text="{Binding Path=TempoVitaUtensile}" MinWidth="100" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Usura €/min : " MinWidth="100" Height="20" />
                            <TextBlock Text="{Binding Path=UsuraEuroMin, StringFormat={}{0:C}}" MinWidth="100" />
                            <Button Content="Re" Command="{Binding Path=UpdateUsuraUtensileCmd}" />
                        </StackPanel>
                    </StackPanel>
                </TabItem>
            </TabControl>
        </Grid>
    </DockPanel>
</UserControl>
